//
//  TabBarViewController.m
//  CWRD
//
//  Created by lanou on 15/9/16.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "TabBarViewController.h"
#import "DailySelectionTableViewController.h"
#import "ClassificationViewController.h"
#import "TopListViewController.h"
//#import "MineTableViewController.h"
#import "MineViewController.h"
#import "IIViewDeckController.h"

@interface TabBarViewController ()

@property (nonatomic,strong)IIViewDeckController *deckViewClass;
@property (nonatomic,strong)IIViewDeckController *deckViewDaily;
@property (nonatomic,strong)IIViewDeckController *deckViewTop;

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    DailySelectionTableViewController *dailyTVC = [[DailySelectionTableViewController alloc]initWithStyle:(UITableViewStylePlain)];
    MineViewController *drawerDaily = [[MineViewController alloc] init];
    self.deckViewDaily = [[IIViewDeckController alloc]initWithCenterViewController:dailyTVC leftViewController:drawerDaily];
    self.deckViewDaily.leftSize = 260;
    dailyTVC = (DailySelectionTableViewController *)self.deckViewDaily;
    UIBarButtonItem *settingDaily = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed: @"Entypo_2630(0)_32"] style:UIBarButtonItemStylePlain target:self action:@selector(dailySetting)];
    [settingDaily setTintColor:[UIColor cyanColor]];
    dailyTVC.navigationItem.leftBarButtonItem = settingDaily;

    //=====================================================================
    
    
    
    ClassificationViewController *classVC = [[ClassificationViewController alloc]init];
    MineViewController *drawerClass = [[MineViewController alloc] init];
    
    self.deckViewClass = [[IIViewDeckController alloc]initWithCenterViewController:classVC leftViewController:drawerClass];
    self.deckViewClass.leftSize = 260;
    classVC = (ClassificationViewController *)self.deckViewClass;
    //我的按钮
    UIBarButtonItem *settingClass = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed: @"Entypo_2630(0)_32"] style:UIBarButtonItemStylePlain target:self action:@selector(classSettingButton)];
    classVC.navigationItem.leftBarButtonItem = settingClass;
    [settingClass setTintColor:[UIColor cyanColor]];
    //=====================================================================

    
    TopListViewController *topListVC = [[TopListViewController alloc]init];
    MineViewController *drawerTop = [[MineViewController alloc] init];
    self.deckViewTop= [[IIViewDeckController alloc]initWithCenterViewController:topListVC leftViewController:drawerTop];
    self.deckViewTop.leftSize = 260;
    topListVC = (TopListViewController *)self.deckViewTop;
    UIBarButtonItem *settingTop = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed: @"Entypo_2630(0)_32"] style:UIBarButtonItemStylePlain target:self action:@selector(topSetting)];
    topListVC.navigationItem.leftBarButtonItem = settingTop;
    [settingTop setTintColor:[UIColor cyanColor]];
    
    [self addChildVC:dailyTVC title:@"每日精选" imageName:@"Entypo_d83d(0)_32" selectedImage:@""];
    [self addChildVC:classVC title:@"分类" imageName:@"classifaction" selectedImage:@""];
    [self addChildVC:topListVC title:@"排行榜" imageName:@"rank" selectedImage:@""];

    
}

- (void)addChildVC:(UIViewController *)childVC title:(NSString *)title imageName:(NSString *)imageName selectedImage:(NSString *)selectedImage {
   
    //设置字体颜色
    self.tabBar.tintColor = [UIColor cyanColor];
    self.tabBar.barTintColor = [UIColor blackColor];

    //设置默认图标(图标不被渲染)
        childVC.tabBarItem.image = [[UIImage imageNamed: imageName]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
        
    //设置选中图标
    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    //设置导航控制器
    UINavigationController *childNVC = [[UINavigationController alloc]initWithRootViewController:childVC];
    
    //设置导航栏文本内容
    childVC.navigationItem.title = title;
    
    
    //设置导航栏文本和填充色
    childNVC.navigationBar.barTintColor = [UIColor clearColor];
    //修改navgation的字体,大小,颜色
    
    [childNVC.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor cyanColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:12.0], NSFontAttributeName, [UIColor clearColor], NSBackgroundColorAttributeName, nil]];
//    childNVC.navigationBar.alpha = 0.5;
    
    //设置文本
    childNVC.tabBarItem.title = title;
    
    childNVC.navigationBar.translucent = NO;
    //修改导航栏颜色
    [childVC.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"daohang"] forBarMetrics:(UIBarMetricsDefault)];
    //将我们设置好的视图控制器添加到TabBarController
    [self addChildViewController:childNVC];
}


//分类跳到"我的"
- (void)classSettingButton{
    [self.deckViewClass toggleLeftView];
}
//每日精选跳到"我的"
-(void)dailySetting{
    [self.deckViewDaily toggleLeftView];
}
//排行榜跳到"我的"
-(void)topSetting{
    [self.deckViewTop toggleLeftView];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
